package com.tourism.website.articledisplay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tourism.website.articledisplay.entity.ArticleCategory;
import com.tourism.website.articledisplay.entity.ArticleImg;
import com.tourism.website.articledisplay.mapper.ArticleCategoryMapper;
import com.tourism.website.articledisplay.service.IArticleCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tourismwebsite.articledisplay.dto.ArticleCategoryDTO;
import com.tourismwebsite.articledisplay.dto.ArticleImgDTO;
import com.tourismwebsite.collection.dto.FavoriteDTO;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyc
 * @since 2024-06-11
 */
@Mapper(componentModel="spring")
interface MsArticleCategoryMapper{
    ArticleCategoryDTO ArticleCategoryToArticleCategoryDTO(ArticleCategory articleCategory);
}
@Service
public class ArticleCategoryServiceImpl extends ServiceImpl<ArticleCategoryMapper, ArticleCategory> implements IArticleCategoryService {
    @Resource
    MsArticleCategoryMapper msArticleCategoryMapper;
    @Override
    public List<ArticleCategoryDTO> queryArticleID(Integer categoryId) {
        LambdaQueryWrapper<ArticleCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ArticleCategory::getCategoryId,categoryId);
        wrapper.select(ArticleCategory::getArticleId);
        List<ArticleCategory> articleCategories = baseMapper.selectList(wrapper);
        List<ArticleCategoryDTO> articleCategoryDTOS = articleCategories.stream()
                .map(articleCategory -> msArticleCategoryMapper.ArticleCategoryToArticleCategoryDTO(articleCategory))
                .collect(Collectors.toList());
        return articleCategoryDTOS;
    }
}
